﻿function isStrictMode(){
    return document.compatMode != "BackCompat";
    }
function getWidth(){
    return isStrictMode() ? Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) : Math.max(document.body.scrollWidth, document.body.clientWidth);
}
function getHeight(){
    return isStrictMode() ? Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) : Math.max(document.body.scrollHeight, document.body.clientHeight);
}

/*tr经过和移开样式*/
function mover(src){
	src.bgColor="#FFFF99";
}
function mout(src)  {
	src.bgColor="#ffffff";
}

/*文本框经过和移开样式*/
function ShowOver(obj,style)
{
    obj.className=style;
}
function ShowOut(obj,style)
{
    obj.className=style;
}

/*输入框必须填写数字*/
function isNum()
{
    if(event.keyCode<45 || event.keyCode>57)
    {
     event.keyCode=0;
    }
} 

//获取参数
function getQueryString(queryName){ 
     var reg = new RegExp("(^|&)"+ queryName +"=([^&]*)(&|$)"); 
     var r = window.location.search.substr(1).match(reg); 
     if (r!=null)
        return unescape(r[2]);
     return
        null; 
}

$(document).ready(function() {
    
    /*按钮事件*/
    $(".btn").bind('mouseenter mouseleave', function() {
        $(this).toggleClass("btnover");
    });
    
    /*列表每页显示个数样式*/
    var temp=getQueryString("PageSize");
    if(temp=="10")
        $("#btnPageSize1").addClass("btnlistOver");
    else if(temp =="20")
        $("#btnPageSize2").addClass("btnlistOver");
    else if(temp == "30")
        $("#btnPageSize3").addClass("btnlistOver");
    
    if(temp==null)
        $("#btnPageSize1").addClass("btnlistOver");
});

/*获取页面显示个数的参数*/
function GetPageHref(_ParamName,_Value)
{
    //是否有参数
    var _IsParams;
    var _Url = document.location.href;
    if (_Url.indexOf("?")>0)
        _IsParams=true;
    else
        _IsParams=false;

    var _GoToUrl;//实际传送地址
    var reg = new RegExp("(^|&)"+_ParamName+"=([^&]*)(&|$)"); 
    var r = window.location.search.substr(1).match(reg); 
    if(_IsParams)
    {
        if (r!=null)
        {
            GoToUrl = window.location.href.replace(r[2],_Value);
        }
        else
            GoToUrl = _Url + "&"+_ParamName+"="+_Value;
    }
    else
         GoToUrl = _Url + "?"+_ParamName+"="+_Value;
    window.location.href = GoToUrl;
}

function funbtnClick(obj)
{
    $(obj).after("<img src='images/loading.gif'/>");
    $(obj).hide();
}

/*列表复选框*/
function checkAll(form)
{
   var chkall= document.getElementById("cheList");
   
   var chkother= document.getElementById("tableData").getElementsByTagName("input"); 
   for (var i=0;i<chkother.length;i++){
      if( chkother[i].type=='checkbox'){
          if(chkall.checked==true){
              chkother[i].checked=true;
          }
          else{
              chkother[i].checked=false;
          }
       }
    }
}

function getElementPos(elementId){
    var ua = navigator.userAgent.toLowerCase();
    var isOpera = (ua.indexOf('opera') != -1);
    var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof 
    var el = document.getElementById(elementId);
    if (el.parentNode === null || el.style.display == 'none') {
        return false;
    }
    var parent = null;
    var pos = [];
    var box;
    if (el.getBoundingClientRect){ //IE 
        box = el.getBoundingClientRect();
        var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
        var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
        return { 
            x: box.left + scrollLeft, 
            y: box.top + scrollTop
        }; 
    } 
    else  if (document.getBoxObjectFor) {// gecko
        box = document.getBoxObjectFor(el); 
        var borderLeft = (el.style.borderLeftWidth) ? parseInt(el.style.borderLeftWidth) : 0;
        var borderTop = (el.style.borderTopWidth) ? parseInt(el.style.borderTopWidth) : 0;
        pos = [box.x - borderLeft, box.y - borderTop]; 
    } 
    else { // safari & opera
        pos = [el.offsetLeft, el.offsetTop];
        parent = el.offsetParent;
        if (parent != el) {
            while (parent) { 
                pos[0] += parent.offsetLeft;
                pos[1] += parent.offsetTop;
                parent = parent.offsetParent;
            }
        }
        if (ua.indexOf('opera') != -1 || (ua.indexOf('safari') != -1 && el.style.position == 'absolute')){
            pos[0] -= document.body.offsetLeft;
            pos[1] -= document.body.offsetTop;
        }
    }
    if (el.parentNode) {
        parent = el.parentNode;
    }
    else {
        parent = null;
    }        
    while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') { // account for any scrolled    ancestors             
        pos[0] -= parent.scrollLeft;
        pos[1] -= parent.scrollTop;
        if (parent.parentNode) { 
            parent = parent.parentNode;
        }
        else {
            parent = null;
        } 
    }
    return { 
        x: pos[0],
        y: pos[1]
    };
}

//图片比例缩放
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
    //参数(图片,允许的宽度,允许的高度)
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
        flag=true;
        if(image.width/image.height>= iwidth/iheight){
            if(image.width>iwidth){  
                ImgD.width=iwidth;
                ImgD.height=(image.height*iwidth)/image.width;
            }else{
                ImgD.width=image.width;  
                ImgD.height=image.height;
            }
            ImgD.alt=image.width+"×"+image.height;
        }else{
            if(image.height>iheight){  
                ImgD.height=iheight;
                ImgD.width=(image.width*iheight)/image.height;        
            }else{
                ImgD.width=image.width;  
                ImgD.height=image.height;
            }
            ImgD.alt=image.width+"×"+image.height;
        }
    }
}